// ==UserScript==
// @name        YE功能增强.07 - [漫画]
// @description 
// @namespace   http://AsionTang.CN
// @copyright   2015+, AsionTang
// @author      AsionTang
// @version     150418.02.01.002
// @iconURL     http://www.dmzj.com/favicon.ico
// @downloadURL https://bitbucket.org/AsionTang/52scriptlibrary/raw/default/YeJS/07.ManHua.user.js
// @match       *://www.u17.com/chapter/*.html*
// @match       *://user.u17.com/favorite/list.php*
// @match       *://manhua.dmzj.com/*
// @grant       none
// @grant       GM_openInTab
// ==/UserScript==
(function() {
    if (window.location.pathname.indexOf('/favorite/list.php') == -1)
        return;
    var items = document.getElementById('form1').getElementsByTagName('li');
    for (var i = 0; i < items.length; i++) {
        var item = items[i];
        var as = item.getElementsByTagName('a');
        var name = as[0].innerText;
        var lastUpate = as[1].innerText;
        var lastRead = as[2].innerText;
        if (lastRead.indexOf('已读') > -1)
            lastRead = as[3].innerText;
        if (lastRead != lastUpate) {
            console.dir(name);
            as[0].style.backgroundColor = 'red';
            as[0].style.color = 'yellow';
        }
    }
}
)();
//================================================================
// 02.【动漫之家】支持双击自动打开所有页面
//================================================================
dbClickOpenAll();
function dbClickOpenAll() {
    if (window.location.host.indexOf('manhua.dmzj.com') == -1)
        return;
    document.ondblclick = openAll;
    function openAll() {
        //获取总页数
        var count = document.getElementById('jump_select').length - 1;

        //获取当前地址
        var currentUrl = window.location.href;

        //判断是否为第一页地址
        if (currentUrl.indexOf('-') != -1) {
            console.log('不是首页：' + currentUrl);
            return;
        }

        //一次性打开所有页面；从第二页开始
        for (var i = 2; i <= count; i++) {
            //拼接完整的URL
            var newUrl = currentUrl.replace('.shtml', '-' + i + '.shtml');
            console.log(i + '地址：' + newUrl);
            GM_openInTab(newUrl, {
                insert: false,
                active: false
            });
        }
    }
}
//================================================================
// 01.【有妖气】修复每一章第一页无法点击图片跳转到第二页的问题
//================================================================
fixSecondPage();
function fixSecondPage() {
    if (window.location.pathname.indexOf('chapter') == -1)
        return;
    document.getElementById('image_trigger').onclick = function() {
        if (document.getElementsByClassName('selectpage')[0].children[0].innerText.indexOf('第1页') == -1)
            return;
        document.getElementsByClassName('page_2')[0].click();
    }
    ;
}
